/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package UI;

import deviceManagement.DeviceManager;
import diskfilesystem.Disk;
import diskfilesystem.Document;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import static java.lang.Thread.sleep;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTree;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import memoryManagement.*;
import processManagement.*;

/**
 *
 * @author Administrator
 */
public class MainInterface extends javax.swing.JFrame {

    /**
     * Creates new form MainInterface
     */
    public static Time time = new Time();                //系统当前时间
    public static DefaultMutableTreeNode top;         //树根
    public DefaultMutableTreeNode parent;      //当前文件的结点
    public String filePath = null;               //当前文件的路径
    public String fileName = null;               //当前文件名
    public Document currentFile = null;              //当前文件对象
    JPopupMenu popMenu;                             //鼠标右键菜单
    public static mem memory = new mem();                   //内存
    public static PCT pct = new PCT();                            //进程表
    public static ProcessManager processManager = new ProcessManager();  //进程管理器
    public static DeviceManager deviceManager = new DeviceManager();  //设备管理器
    public static Disk disk = new Disk();             //硬盘
    public static ArrayList<Document> fileObject = new ArrayList();      //文件（夹）对象表
    static boolean auto = false;      //自动生成进程
    static int indexOfLog=1;       //最新日志号,从1记起，0号日志为进程管理器初始化完毕

    public MainInterface() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jTextField3 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTable4 = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jPanel5 = new JPane(disk);
        jPanel6 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        top = new DefaultMutableTreeNode("C");
        DefaultMutableTreeNode child=null;
        Document root=new Document("C");
        root.attribute='m';
        root.begin=2;
        root.size=1;
        fileObject.add(root);             //将根目录的文件对象加入到文件对象列表中
        filePath="C";
        if(!(root.exists())){
            root.mkdir();
        }
        jTree = new javax.swing.JTree(top);
        jTextField4 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        jCheckBox1 = new javax.swing.JCheckBox();
        jPanel2 = memory.frame.p;
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        canvas1 = new java.awt.Canvas();
        panel1 = new java.awt.Panel();
        jLabel3 = new javax.swing.JLabel();
        panel2 = new java.awt.Panel();
        jLabel4 = new javax.swing.JLabel();
        panel3 = new java.awt.Panel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("模拟操作系统");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "进程管理", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("楷体", 1, 12))); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "进程ID", "优先级", "所需内存", "设备及台数","当前状态","提交时间","已执行时间","持续时间","所需执行时间"
            }
        ));
        jTable1.setEnabled(false);
        jTable1.setName(""); // NOI18N
        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setHorizontalAlignment(SwingConstants.CENTER);
        jTable1.setDefaultRenderer(Object.class, r);
        jScrollPane3.setViewportView(jTable1);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "进程ID", "优先级", "所需内存", "设备及台数","当前状态","提交时间","已执行时间","持续时间","所需执行时间"
            }
        ));
        //DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setHorizontalAlignment(SwingConstants.CENTER);
        jTable2.setDefaultRenderer(Object.class, r);
        jTable2.setEnabled(false);
        jScrollPane4.setViewportView(jTable2);

        jTextField3.setEditable(false);
        jTextField3.setText("就绪队列：");
        jTextField3.setBorder(null);
        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });

        jTextField5.setEditable(false);
        jTextField5.setText("执行队列：");
        jTextField5.setBorder(null);
        jTextField5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField5ActionPerformed(evt);
            }
        });

        jTextField6.setEditable(false);
        jTextField6.setText("阻塞队列：");
        jTextField6.setBorder(null);
        jTextField6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField6ActionPerformed(evt);
            }
        });

        jScrollPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "进程执行情况", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("楷体", 1, 12))); // NOI18N

        jTextArea1.setEditable(false);
        jTextArea1.setColumns(20);
        jTextArea1.setRows(0);
        jTextArea1.setText("");
        jScrollPane2.setViewportView(jTextArea1);

        jTable4.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "进程ID", "优先级", "所需内存", "设备及台数","当前状态","提交时间","已执行时间","持续时间","所需执行时间"
            }
        ));
        //DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setHorizontalAlignment(SwingConstants.CENTER);
        jTable4.setDefaultRenderer(Object.class, r);
        jTable4.setEnabled(false);
        jScrollPane6.setViewportView(jTable4);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3)
            .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "设备分配情况", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("楷体", 1, 12))); // NOI18N

        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new String[][]{
                {"A设备", "空闲"},
                {"B设备1号", "空闲"},
                {"B设备2号", "空闲"},
                {"C设备1号", "空闲"},
                {"C设备2号", "空闲"}
            },
            new String [] {
                "可用设备", "分配情况"
            }
        ));
        DefaultTableCellRenderer render = new DefaultTableCellRenderer();
        render.setHorizontalAlignment(SwingConstants.CENTER);
        jTable3.setDefaultRenderer(Object.class, render);
        jTable3.setEnabled(false);
        jScrollPane5.setViewportView(jTable3);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 609, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "磁盘占用情况", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("楷体", 1, 12))); // NOI18N

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 527, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 204, Short.MAX_VALUE)
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "文件管理", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("楷体", 1, 12))); // NOI18N

        //jTree.setSelectionPath(jTree.getPathForRow(0));
        popMenu=new JPopupMenu();
        final JMenuItem addFile=new JMenuItem("新建文件(夹)");
        final JMenuItem copy=new JMenuItem("复制到");
        final JMenuItem reName=new JMenuItem("重命名");
        final JMenuItem delFile=new JMenuItem("删除文件（夹）");
        final JMenuItem attribute=new JMenuItem("属性");
        popMenu.add(addFile);
        popMenu.add(copy);
        popMenu.add(reName);
        popMenu.add(delFile);
        popMenu.add(attribute);
        jTree.add(popMenu);

        MainInterface.findAllChildren(top, filePath);
        currentFile=new Document(filePath);
        jTree.updateUI();

        jTree.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                if (e.getButton() == 1 && e.getClickCount() == 2) {//鼠标左键双击
                    String treePath = jTree.getSelectionPath().toString();
                    filePath=MainInterface.getFilePathByTreePath(treePath);
                    fileName=MainInterface.getNameByTreePath(treePath);
                    currentFile=MainInterface.findFileObjectByFilePath(filePath);
                    jTree.updateUI();
                    //FileFrame frame=new FileFrame(filePath);

                    //frame.setVisible(true);
                    if(currentFile.getName().indexOf(".")!=-1){
                        try{
                            Runtime.getRuntime().exec("C:\\WINDOWS\\system32\\notepad.exe "+filePath);
                        } catch (Exception ex){
                            ex.printStackTrace();
                        }
                    }
                }
                if (e.getButton() == 3 && e.getClickCount() == 1) {//鼠标右键单击
                    popMenu.show(jTree, e.getX(), e.getY());
                    jTree.setSelectionPath(jTree.getClosestPathForLocation(e.getX(), e.getY()));
                    String treePath = jTree.getSelectionPath().toString();
                    filePath=MainInterface.getFilePathByTreePath(treePath);
                    fileName=MainInterface.getNameByTreePath(treePath);
                    currentFile=MainInterface.findFileObjectByFilePath(filePath);
                    //System.out.println(filePath);
                }
            }
        });

        //新建文件（夹）
        addFile.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                if(e.getSource()==addFile){
                    String s=JOptionPane.showInputDialog("请输入文件(夹)名称(若为文件后缀应为.e)","new.e");
                    //if(s==""||s==null) System.out.print("jjjjj");
                    if(s!=null||s!=""){
                        Document newFile=new Document(filePath+"\\"+s);
                            if(newFile.exists()){
                                JOptionPane.showMessageDialog(null,"文件已存在，建立文件失败");
                            }else{
                                fileObject.add(newFile);
                                parent =(DefaultMutableTreeNode)jTree.getLastSelectedPathComponent();
                                parent.add(new DefaultMutableTreeNode(s));
                                if (newFile.getName().indexOf(".") == -1) {
                                    newFile.mkdir();
                                    disk.createDirectory(newFile);
                                } else {
                                    try{
                                        newFile.createNewFile();
                                    }catch(IOException ex){
                                        System.out.println(ex.toString());
                                    }
                                    disk.createFile(newFile);
                                }
                                jTree.updateUI();
                            }
                        }
                        MainInterface.showDisk();
                    }
                }
            });

            //重命名文件（夹）
            reName.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    if(e.getSource()==reName){
                        String s=JOptionPane.showInputDialog("请输入新名称","new.e");
                        if(s!=null||s!=""){
                            //System.out.println(currentFile.getPath()+"\\"+s);
                                String newPath=currentFile.getParent()+"\\"+s;
                                Document newFile=currentFile.rename(currentFile,newPath);
                                if(newFile.exists()){
                                    JOptionPane.showMessageDialog(null,"文件已存在，重命名文件失败");
                                }else{
                                    if(currentFile.getName().indexOf(".")==-1){
                                        currentFile.copyFolder(currentFile.getPath(), newPath);
                                    }else{
                                        currentFile.copyFile(currentFile.getPath(), newPath);
                                    }
                                    fileObject.remove(currentFile);
                                    currentFile.delete();
                                    currentFile=newFile;
                                    fileObject.add(currentFile);
                                    disk.rename(currentFile);
                                    parent =(DefaultMutableTreeNode)jTree.getLastSelectedPathComponent();
                                    parent.setUserObject(s);
                                    jTree.updateUI();
                                }
                            }
                        }
                    }
                });

                //复制文件（夹）
                copy.addActionListener(new ActionListener(){
                    public void actionPerformed(ActionEvent e){
                        if(e.getSource()==copy){
                            String newPath=JOptionPane.showInputDialog("请输入新路径",filePath);
                            if(newPath!=null||newPath!=""){
                                //System.out.println(currentFile.getPath()+"\\"+s);
                                    Document newFile=new Document(newPath);
                                    fileObject.add(newFile);
                                    if(currentFile.getName().indexOf(".")==-1){
                                        currentFile.copyFolder(filePath, newPath);
                                        disk.createDirectory(newFile);
                                    }else{
                                        currentFile.copyFile(filePath, newPath);
                                        disk.createFile(newFile);
                                    }

                                    parent=MainInterface.getTreeNodeByNodeName(MainInterface.getNameByFilePath(newFile.getParent()));
                                    DefaultMutableTreeNode newChild=new DefaultMutableTreeNode(MainInterface.getNameByFilePath(newPath));
                                    //System.out.println(newFile.getParent()+"  "+newPath);
                                    parent.add(newChild);
                                    jTree.updateUI();
                                }
                                MainInterface.showDisk();
                            }
                        }

                    });

                    //删除文件（夹）
                    delFile.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e){
                            if(e.getSource()==delFile){
                                if(currentFile.getName()=="C")JOptionPane.showMessageDialog(null,"不能删除磁盘");
                                else{
                                    if(currentFile.getName().indexOf(".")==-1){
                                        Document[] files=currentFile.listFiles();
                                        if(files.length>=1){
                                            JOptionPane.showMessageDialog(null,"不能删除非空目录");
                                        }else{
                                            disk.deleteDirectory(currentFile);
                                            currentFile.delete();
                                            parent =(DefaultMutableTreeNode)jTree.getLastSelectedPathComponent();
                                            parent.removeFromParent();
                                            jTree.updateUI();
                                        }
                                    }else {
                                        disk.deleteFile(currentFile);
                                        currentFile.delete();
                                        DefaultMutableTreeNode p =(DefaultMutableTreeNode)jTree.getLastSelectedPathComponent();
                                        p.removeFromParent();
                                        jTree.updateUI();
                                    }
                                }
                                MainInterface.showDisk();
                            }
                        }
                    });

                    attribute.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e){
                            if(e.getSource()==attribute){
                                JFrame frame1=new JFrame("属性");
                                AttributePanel pane=new AttributePanel(currentFile);
                                frame1.setSize(400, 600);
                                //disk.showFileInfo(currentFile);
                                frame1.add(pane);
                                frame1.pack();
                                frame1.setVisible(true);
                                //MainInterface.showAttribute();
                                //System.out.print("ppppppppppp");
                            }
                        }
                    });
                    jScrollPane1.setViewportView(jTree);

                    jTextField4.setEditable(false);
                    jTextField4.setFont(new java.awt.Font("宋体", 1, 24)); // NOI18N
                    jTextField4.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
                    jTextField4.setText("系统时间：");
                    jTextField4.setBorder(null);
                    jTextField4.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jTextField4ActionPerformed(evt);
                        }
                    });

                    jTextField7.setEditable(false);
                    jTextField7.setFont(new java.awt.Font("宋体", 1, 24)); // NOI18N
                    jTextField7.setHorizontalAlignment(javax.swing.JTextField.LEFT);
                    jTextField7.setText("00:00:00");
                    jTextField7.setBorder(null);
                    jTextField7.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jTextField7ActionPerformed(evt);
                        }
                    });

                    jTextField2.setEditable(false);
                    jTextField2.setFont(new java.awt.Font("宋体", 1, 24)); // NOI18N
                    jTextField2.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
                    jTextField2.setText("时间片：");
                    jTextField2.setBorder(null);

                    jComboBox1.setFont(new java.awt.Font("宋体", 1, 24)); // NOI18N
                    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "5","1", "2", "10" }));
                    jComboBox1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jComboBox1ActionPerformed(evt);
                        }
                    });

                    jCheckBox1.setFont(new java.awt.Font("宋体", 1, 24)); // NOI18N
                    jCheckBox1.setText("自动生成进程");
                    jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jCheckBox1ActionPerformed(evt);
                        }
                    });

                    javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
                    jPanel6.setLayout(jPanel6Layout);
                    jPanel6Layout.setHorizontalGroup(
                        jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel6Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel6Layout.createSequentialGroup()
                                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                                        .addComponent(jTextField2))
                                    .addGap(18, 18, 18)
                                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(jPanel6Layout.createSequentialGroup()
                                    .addComponent(jCheckBox1)
                                    .addGap(2, 2, 2)))
                            .addContainerGap(21, Short.MAX_VALUE))
                    );
                    jPanel6Layout.setVerticalGroup(
                        jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel6Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                .addGroup(jPanel6Layout.createSequentialGroup()
                                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(26, 26, 26)
                                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(18, 18, 18)
                                    .addComponent(jCheckBox1)
                                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    );

                    jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "内存分配情况", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("黑体", 1, 12))); // NOI18N

                    jLabel1.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
                    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
                    jLabel1.setText("Tips：");

                    jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
                    jLabel2.setText("剩余内存 <= 128");
                    jLabel2.setToolTipText("");

                    panel1.setBackground(new java.awt.Color(220, 22, 10));

                    javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1);
                    panel1.setLayout(panel1Layout);
                    panel1Layout.setHorizontalGroup(
                        panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 20, Short.MAX_VALUE)
                    );
                    panel1Layout.setVerticalGroup(
                        panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 19, Short.MAX_VALUE)
                    );

                    jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
                    jLabel3.setText("剩余内存 <= 256 ");
                    jLabel3.setToolTipText("");

                    panel2.setBackground(new java.awt.Color(222, 222, 10));

                    javax.swing.GroupLayout panel2Layout = new javax.swing.GroupLayout(panel2);
                    panel2.setLayout(panel2Layout);
                    panel2Layout.setHorizontalGroup(
                        panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 20, Short.MAX_VALUE)
                    );
                    panel2Layout.setVerticalGroup(
                        panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 19, Short.MAX_VALUE)
                    );

                    jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
                    jLabel4.setText("剩余内存 > 256 ");
                    jLabel4.setToolTipText("");

                    panel3.setBackground(new java.awt.Color(20, 175, 48));

                    javax.swing.GroupLayout panel3Layout = new javax.swing.GroupLayout(panel3);
                    panel3.setLayout(panel3Layout);
                    panel3Layout.setHorizontalGroup(
                        panel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 20, Short.MAX_VALUE)
                    );
                    panel3Layout.setVerticalGroup(
                        panel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 19, Short.MAX_VALUE)
                    );

                    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
                    jPanel2.setLayout(jPanel2Layout);
                    jPanel2Layout.setHorizontalGroup(
                        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel1)
                            .addGap(1, 1, 1)
                            .addComponent(panel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(panel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(panel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(canvas1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    );
                    jPanel2Layout.setVerticalGroup(
                        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(canvas1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1)
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(panel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(panel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(panel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addContainerGap(135, Short.MAX_VALUE))
                    );

                    jMenu1.setText("文件");

                    jMenuItem1.setText("新建文件");
                    jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jMenuItem1ActionPerformed(evt);
                        }
                    });
                    jMenu1.add(jMenuItem1);

                    jMenuBar1.add(jMenu1);

                    jMenu2.setText("编辑");
                    jMenuBar1.add(jMenu2);

                    setJMenuBar(jMenuBar1);

                    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
                    getContentPane().setLayout(layout);
                    layout.setHorizontalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(2, 2, 2)
                                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    );
                    layout.setVerticalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addContainerGap())
                    );

                    pack();
                }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:

    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField3ActionPerformed

    private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField5ActionPerformed

    private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField6ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField6ActionPerformed

    private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField4ActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        if (jCheckBox1.isSelected()) {
            auto = true;
        } else {
            auto = false;
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField7ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField7ActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
       pct.T=Integer.parseInt((String) jComboBox1.getSelectedItem());
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */

        /*
         try {
         for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
         if ("Nimbus".equals(info.getName())) {
         javax.swing.UIManager.setLookAndFeel(info.getClassName());
         break;
         }
         }
         } catch (ClassNotFoundException ex) {
         java.util.logging.Logger.getLogger(MainInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
         } catch (InstantiationException ex) {
         java.util.logging.Logger.getLogger(MainInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
         } catch (IllegalAccessException ex) {
         java.util.logging.Logger.getLogger(MainInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
         java.util.logging.Logger.getLogger(MainInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
         }
        
         */
        //</editor-fold>

        /* Create and display the form */
        //Document f=new Document("pp.e");
        //System.out.print(f.read());
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                MainInterface s = new MainInterface();
                s.setVisible(true);
                //s.memory.create(0, 32);
            }
        });
        Thread TimeDemo = new Thread(time);
        TimeDemo.start();
        Thread ProcessDemo = new Thread(processManager);
        ProcessDemo.start();

        /*  
         */
    }

    public static void showTime() {
        jTextField7.setText(toTime(getCurrentTime()));
    }

    public static void showDisk() {     //显示磁盘占用情况
        jPanel5.repaint();

    }

    public static void showLog() {   //显示进程执行情况
        for ( ; indexOfLog < pct.log.size(); indexOfLog++) {
            //jTextArea1.append(pct.log.get(i)+"\n");
            if(!pct.log.get(indexOfLog).equals(pct.log.get(indexOfLog-1)))
            jTextArea1.insert(pct.log.get(indexOfLog) +" "+toTime(time.currentTime)+ "\n", 0);
        }
        //jTextArea1.setCaretPosition(jTextArea1.getText().length());     //让日志自动滚到最底部
        //pct.log.clear();
    }

    public static void showPCT() {      //显示三种进程队列及进程执行情况
        DefaultTableModel j1 = (DefaultTableModel) jTable1.getModel();      //执行队列面板
        while (j1.getRowCount() != 0) {
            j1.removeRow(0);
        }
        for (int i = 0; i < pct.carry.size(); i++) {
            processManagement.Process p = pct.carry.get(i);
            p.execute_time++;
            p.duration_time++;
            //进程状态，0表示执行，1表示就绪，2表示阻塞
            String ss = "";  //进程状态
            if (p.status == 0) {
                ss = "执行";
            } else if (p.status == 1) {
                ss = "就绪";
            } else {
                ss = "阻塞";
            }
            String dd = "";  //所需设备及台数
            if (p.device[0] != 0) {
                dd = dd + "A" + String.valueOf(p.device[0]) + "台";
            }
            if (p.device[1] != 0) {
                dd = dd + "B" + String.valueOf(p.device[1]) + "台";
            }
            if (p.device[2] != 0) {
                dd = dd + "C" + String.valueOf(p.device[2]) + "台";
            }
            if(dd=="")dd="无";
            String ff = "";   //进程完成时间
            if (p.finish_time != 0) {
                ff = String.valueOf(p.finish_time);
            }
            /*
            String[] t = new String[]{
                "进程ID", "优先级", "所需内存", "所需设备及台数", "当前状态", "提交时间", "已执行时间", "持续时间", "完成时间", "所需执行时间"
            };
            String[][] s=new String[1][10];
            s[0][0]=String.valueOf(p.ID);
                s[0][1]=String.valueOf(p.priority);
                s[0][2]=String.valueOf(p.size);
                s[0][3]=dd;
                s[0][4]=ss;
                s[0][5]=String.valueOf(p.submit_time);
                s[0][6]=String.valueOf(p.execute_time);
                s[0][7]=String.valueOf(p.duration_time);
                s[0][8]=ff;
                s[0][9]=String.valueOf(p.require_time);
            */
            String[] s=new String[]{
                String.valueOf(p.ID),
                String.valueOf(p.priority),
                String.valueOf(p.size),
                dd,
                ss,
                String.valueOf(p.submit_time),
                String.valueOf(p.execute_time),
                String.valueOf(p.duration_time),
                //ff,
                String.valueOf(p.require_time)
            };
            //j1.setDataVector(s, t);
            //j1.insertRow(0, s);
            j1.addRow(s);
        }
        DefaultTableModel j2 = (DefaultTableModel) jTable2.getModel();  //就绪队列面板
        while (j2.getRowCount() != 0) {
            j2.removeRow(0);
        }
        for (int i = 0; i < pct.ready.size(); i++) {
            processManagement.Process p = pct.ready.get(i);
            p.duration_time++;
            //进程状态，0表示执行，1表示就绪，2表示阻塞
            String ss = "";  //进程状态
            if (p.status == 0) {
                ss = "执行";
            } else if (p.status == 1) {
                ss = "就绪";
            } else {
                ss = "阻塞";
            }
            String dd = "";  //所需设备及台数
            if (p.device[0] != 0) {
                dd = dd + "A" + String.valueOf(p.device[0]) + "台";
            }
            if (p.device[1] != 0) {
                dd = dd + "B" + String.valueOf(p.device[1]) + "台";
            }
            if (p.device[2] != 0) {
                dd = dd + "C" + String.valueOf(p.device[2]) + "台";
            }
            if(dd=="")dd="无";
            String ff = "";   //进程完成时间
            if (p.finish_time != 0) {
                ff = String.valueOf(p.finish_time);
            }
            String[] s = {String.valueOf(p.ID),
                String.valueOf(p.priority),
                String.valueOf(p.size),
                dd,
                ss,
                String.valueOf(p.submit_time),
                String.valueOf(p.execute_time),
                String.valueOf(p.duration_time),
                //ff,
                String.valueOf(p.require_time)
            };
            //j2.insertRow(0, s);
            j2.addRow(s);
        }
        DefaultTableModel j4 = (DefaultTableModel) jTable4.getModel();  //阻塞队列面板
        while (j4.getRowCount() != 0) {
            j4.removeRow(0);
        }
        for (int i = 0; i < pct.block.size(); i++) {
            processManagement.Process p = pct.block.get(i);
            p.duration_time++;
            //进程状态，0表示执行，1表示就绪，2表示阻塞
            String ss = "";  //进程状态
            if (p.status == 0) {
                ss = "执行";
            } else if (p.status == 1) {
                ss = "就绪";
            } else {
                ss = "阻塞";
            }
            String dd = "";  //所需设备及台数
            if (p.device[0] != 0) {
                dd = dd + "A" + String.valueOf(p.device[0]) + "台";
            }
            if (p.device[1] != 0) {
                dd = dd + "B" + String.valueOf(p.device[1]) + "台";
            }
            if (p.device[2] != 0) {
                dd = dd + "C" + String.valueOf(p.device[2]) + "台";
            }
            if(dd=="")dd="无";
            String ff = "";   //进程完成时间
            if (p.finish_time != 0) {
                ff = String.valueOf(p.finish_time);
            }
            String[] s = {String.valueOf(p.ID),
                String.valueOf(p.priority),
                String.valueOf(p.size),
                dd,
                ss,
                String.valueOf(p.submit_time),
                String.valueOf(p.execute_time),
                String.valueOf(p.duration_time),
                //ff,
                String.valueOf(p.require_time)
            };
            //j4.insertRow(0, s);
            j4.addRow(s);
        }
    }

    public static void showDevice() {   //显示设备分配情况
        DefaultTableModel j3 = (DefaultTableModel) jTable3.getModel();
        //System.out.println(j3.getRowCount() + "  " + j3.getColumnCount());
        while (j3.getRowCount() != 0) {
            j3.removeRow(0);
        }
        String a, b1, b2, c1, c2;
        if (deviceManager.A1.work == true) {
            a = "占用";
        } else {
            a = "空闲";
        }
        if (deviceManager.B1.work == true) {
            b1 = "占用";
        } else {
            b1 = "空闲";
        }
        if (deviceManager.B2.work == true) {
            b2 = "占用";
        } else {
            b2 = "空闲";
        }
        if (deviceManager.C1.work == true) {
            c1 = "占用";
        } else {
            c1 = "空闲";
        }
        if (deviceManager.C2.work == true) {
            c2 = "占用";
        } else {
            c2 = "空闲";
        }
        String[] title = new String[]{
            "可用设备", "分配情况"
        };
        String[] s1=new String[]{"A设备", a};
        String[] s2=new String[]{"B设备1号", b1};
        String[] s3=new String[]{"B设备2号", b2};
        String[] s4=new String[]{"C设备1号", c1};
        String[] s5=new String[]{"C设备2号", c2};
        j3.addRow(s1);
        j3.addRow(s2);
        j3.addRow(s3);
        j3.addRow(s4);
        j3.addRow(s5);
        
    }

    public static void showMemory() {   //显示内存分配情况
        //jPanel2.repaint();
    }

    public static void autoCreate() {          //当work为true，自动生成进程
        if (auto == true) {
            pct.createProcess(memory, deviceManager);
        }
    }

    public static void findAllChildren(DefaultMutableTreeNode p, String filePath) {
        Document d = new Document(filePath);
        //System.out.println(filePath);
        if (d.isDirectory()) {
            Document[] fileList = d.listFiles();
            //System.out.println(fileList.length);
            if (p.isLeaf()) {
                for (Document fileList1 : fileList) {
                    fileList1 = new Document(d.getPath() + '\\' + fileList1.getName());
                    fileObject.add(fileList1);
                    DefaultMutableTreeNode child = new DefaultMutableTreeNode(fileList1.getName());
                    //System.out.println(fileList1.getPath());
                    if (fileList1.getName().indexOf(".") == -1) {
                        disk.createDirectory(fileList1);
                        MainInterface.findAllChildren(child, fileList1.getPath());
                    } else {
                        disk.createFile(fileList1);
                    }
                    p.add(child);
                }
            }
        }
    }

    public static String getNameByFilePath(String path){//通过文件路径获取文件的名称
        String t[] = path.split("\\\\");
        return t[t.length - 1];
    }
    
    public static String getNameByTreePath(String treePath) {
        String t[] = treePath.split(", ");
        return t[t.length - 1].substring(0, t[t.length - 1].length() - 1);
    }

    public static String getFilePathByTreePath(String treePath) {
        String t[] = treePath.split(", ");
        String s = "";
        for (int i = 0; i < t.length; i++) {
            if (i == 0) {
                t[i] = t[i].substring(1);
            }
            t[i] = t[i].trim();
            if (i != t.length - 1) {
                s = s + t[i] + "\\";
            } else {
                t[i] = t[i].substring(0, t[i].length() - 1);
                //System.out.print(t[i]);
                s = s + t[i];
            }
        }
        return s;
    }

    public static Document findFileObjectByFilePath(String filePath) {
        for (int i = 0; i < fileObject.size(); i++) {
            if (fileObject.get(i).getPath().equals(filePath)) {
                return fileObject.get(i);
            }
        }
        return null;
    }

    public static int getCurrentTime() {
        return time.currentTime;
    }

    public static String toTime(int t) {
        int h = t / 3600;
        int m = t % 3600 / 60;
        int s = t % 60;
        String h1 = null, m1 = null, s1 = null;
        if (h < 10) {
            h1 = "0" + String.valueOf(h);
        } else {
            h1 = String.valueOf(h);
        }
        if (m < 10) {
            m1 = "0" + String.valueOf(m);
        } else {
            m1 = String.valueOf(m);
        }
        if (s < 10) {
            s1 = "0" + String.valueOf(s);
        } else {
            s1 = String.valueOf(s);
        }
        return h1 + ":" + m1 + ":" + s1;
    }
    
    public static DefaultMutableTreeNode getTreeNodeByNodeName(String name){    
        //通过文件名称获取对应的树节点
        Enumeration nodes0= top.children();
        ArrayList<DefaultMutableTreeNode> nodes=Collections.list(nodes0);
        for(int i=0;i<nodes.size();i++){
            System.out.println(nodes.get(i).toString());
            if(nodes.get(i).toString().equals(name))
                return nodes.get(i);
        }
        return null;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Canvas canvas1;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private static javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private static javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    public static javax.swing.JTable jTable1;
    public static javax.swing.JTable jTable2;
    public static javax.swing.JTable jTable3;
    public static javax.swing.JTable jTable4;
    public static javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private static javax.swing.JTextField jTextField7;
    public javax.swing.JTree jTree;
    private java.awt.Panel panel1;
    private java.awt.Panel panel2;
    private java.awt.Panel panel3;
    // End of variables declaration//GEN-END:variables

}
